package com.tedu.exception.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * <p>
 *
 * </p>
 *
 * @author Song
 * @since 2020/10/10
 */
@Controller
public class ModuleController {

    @RequestMapping("doHandleRequest/{n1}/{n2}")
    @ResponseBody
    public String doHandleRequest(@PathVariable("n1")Integer n1, @PathVariable("n2") Integer n2){


        //try {
            Integer result =n1/n2;
            return ""+result;
       // }catch (ArithmeticException e){
       //     return e.getMessage();
       // }
    }

    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody
    public String doHandleArithmeticException(ArithmeticException e){
        e.printStackTrace();
        System.out.println(this.getClass().getName());
        return "计算过程中出现了异常，异常信息为"+e.getMessage();
    }
}
